package com.sca.deal.controller;

import com.sca.deal.order.entity.Order;
import com.sca.deal.product.entity.CommonResult;
import com.sca.deal.service.DealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
public class DealController {

    @Resource
    private DealService dealService;

    @PostMapping("/consumer/deal/create")
    public CommonResult<Order> createOrder(@RequestBody Order payment) {
        try {
            int result = dealService.create(payment);
            log.info("****插入结果：" + result);
            if (result > 0) {
                return new CommonResult(200, "插入数据库成功", result);
            } else {
                return new CommonResult(444, "插入数据库失败", null);
            }
        } catch (Exception e) {
            log.info(e.toString());
            return new CommonResult(500, "插入数据库失败", null);
        }
    }
}
